
package com.caration.shell.settings;

import android.media.AudioManager;

import com.caration.shell.cr3d.SharedData;

public final class RingerModeManager {
    private static final String SYNC = "sync";
    private static RingerModeManager sInstance;
    private int mRingerMode;
    private IconTexture mIconTexture;
    // private RenderRunnable e;
    private AudioManager mAudioManager;

    public static RingerModeManager getInstance() {
        synchronized (SYNC) {
            if (sInstance == null)
                sInstance = new RingerModeManager();
        }
        return sInstance;
    }

    // static void a(x x1) {
    // x1.e = null;
    // }

    public final void init(IconTexture iconTexture) {
        mIconTexture = iconTexture;
        mAudioManager = (AudioManager) SharedData.getContext().getSystemService("audio");
        mRingerMode = mAudioManager.getRingerMode();
        setupIcon();
    }

    public final void setRingerMode() {
        mAudioManager = (AudioManager) SharedData.getContext().getSystemService("audio");
        if (mRingerMode != 2) {
            if (mRingerMode != 0) {
                if (mRingerMode == 1)
                    mAudioManager.setRingerMode(2);
            } else {
                mAudioManager.setRingerMode(1);
            }
        } else {
            mAudioManager.setRingerMode(0);
        }
    }

    public final void setupIcon() {
        if (mIconTexture != null)
            switch (mRingerMode) {
                case 0: // '\0'
                    mIconTexture.setupTexture(1);
                    break;

                case 1: // '\001'
                    mIconTexture.setupTexture(2);
                    break;

                case 2: // '\002'
                    mIconTexture.setupTexture(0);
                    break;
            }
    }

    //TODO: 更新 并 刷新图标纹理
    public final void update() {
//        if (com.censivn.C3DEngine.a.a() != null && StaticShared.getContext() != null && f != null) {
//            mRingerMode = mAudioManager.getRingerMode();
//            if (e != null) {
//                com.censivn.C3DEngine.a.a().b(e);
//                e = null;
//            }
//            e = new y(this);
//            if (j.a().b())
//                e.autoInvalidate = true;
//            com.censivn.C3DEngine.a.a().a(e);
//            if (mIconTexture != null) {
//                e _tmp = mIconTexture;
//                IconTexture.q();
//            }
//        }
    }
}
